import createElement from "./createElement.js";
import updateChildren from './updateChildren.js'
export default function (oldVnode, newVnode) {
    // console.log(oldVnode.children);
    // console.log(newVnode.children);
    if (newVnode.children == undefined) {
        // console.log('新节点没有children,直接覆盖旧的');
        if (newVnode.text !== oldVnode.text) {
            // console.log('文本不同');
            oldVnode.elm.innerText = newVnode.text
        }
    } else {
        if (oldVnode.children !== undefined && oldVnode.children.length > 0) {
            // console.log('新有,旧有',oldVnode.elm, oldVnode.children, newVnode.children);
            updateChildren(oldVnode.elm, oldVnode.children, newVnode.children)
        } else {
            // console.log('新有,旧无');
            // 将旧节点清空 可能有文本节点
            oldVnode.elm.innerHTML = ''
            // 遍历新的子节点添加到旧节点
            for (const child of newVnode.children) {
                let childDom = createElement(child)
                oldVnode.elm.appendChild(childDom)
            }
        }
    }
}